﻿	<%@ taglib prefix='c' uri='http://java.sun.com/jsp/jstl/core'%>
	<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
	<%@ page import="com.cxx.purchasecharge.component.utils.ComponentConstants"%>
	<%@ page import="com.cxx.purchasecharge.component.bean.TimeFrame"%>
	
	<script type="text/javascript">
		var onPaymentAccountSelectStartDate = function (date) 
		{
			$('#toolbar-paymentDetail #advanceSearchSpan #timeFrame').combobox('setValue', 'CUSTOMIZE');
		}
		var onPaymentAccountSelectTimeFrame = function(record) 
		{
			setInitialPaymentDetailTimeFrame(record.value);
		}
		var onSearchPaymentAccountByAdvance = function () 
		{
			var startDate = $('#toolbar-paymentDetail #advanceSearchSpan #startDate').combo('getValue');
			var endDate = $('#toolbar-paymentDetail #advanceSearchSpan #endDate').combo('getValue');
			var paymentId = $('#toolbar-paymentDetail #advanceSearchSpan #paymentId').val();
			var customerId = $('#toolbar-paymentDetail #advanceSearchSpan #customerId').combo('getValue');
			if((startDate != '' && endDate == '') || (startDate == '' && endDate != '')) 
			{
				$.messager.alert('警告','开始时间和结束时间必须同时填!','warning');
				return;
			}
			if(startDate == '' && endDate == '' && customerId == '') 
			{
				$.messager.alert('警告','请填写查询条件!','warning');
				return;
			}
			
			$('#dg-payment-detail').datagrid('reload');
			//loadGridData ('#dg-payment-detail', '<c:url value='/paymentAccount/getModelBySearchForm.html' />', {page:pageInfo.page, rows:pageInfo.rows, startDate:startDate, endDate:endDate, customerId:customerId, paymentId:paymentId});
		}
		var onBeforeLoadPaymentAccount = function (param) 
		{
			var startDate = $('#toolbar-paymentDetail #advanceSearchSpan #startDate').combo('getValue');
			var endDate = $('#toolbar-paymentDetail #advanceSearchSpan #endDate').combo('getValue');
			var paymentId = $('#toolbar-paymentDetail #advanceSearchSpan #paymentId').val();
			var customerId = $('#toolbar-paymentDetail #advanceSearchSpan #customerId').combo('getValue');
			if(customerId == undefined) 
			{
				customerId = '';
			}
			if(startDate == '' && endDate == '' && customerId == '') 
			{
				var timeFrame = $('#toolbar-paymentDetail #advanceSearchSpan #timeFrame').combo('getValue');
				setInitialPaymentDetailTimeFrame(timeFrame);
				
				startDate = $('#toolbar-paymentDetail #advanceSearchSpan #startDate').combo('getValue');
				endDate = $('#toolbar-paymentDetail #advanceSearchSpan #endDate').combo('getValue');
			}
			
			if(param.page == undefined || param.page == 0) 
			{
				param.page = 1;
			}
			$('#dg-payment-detail').datagrid('options').url = "<c:url value='/paymentAccount/getModelBySearchForm.html' />?startDate="+startDate+"&endDate="+endDate+"&customerId="+customerId+"&paymentId="+paymentId+"&page="+param.page;
			return true;
		}
	
		var paymentAccountActionStyler = function (value,row,index) 
		{
			return "<a href='javascript:void(0)' onclick='showSearchPaymentDetailDialog("+index+")' style='text-decoration: underline'>查看详情</a>";
		}
		var defaultPaymentDetailTimeFrame = 'RECENT_SEVEN_DAYS';
		var showSearchPaymentDetailDialog = function (index) 
		{
			$('#dg-paymentAccount').datagrid('selectRow',index);
			var payment = $('#dg-paymentAccount').datagrid('getSelected');
			$('#toolbar-paymentDetail #advanceSearchSpan #paymentId').val(payment.id);
			setInitialPaymentDetailTimeFrame(defaultPaymentDetailTimeFrame);
			$('#toolbar-paymentDetail #advanceSearchSpan #timeFrame').combobox('setValue', defaultPaymentDetailTimeFrame);
			$('#dlg-view-paymentAccount').dialog('open').dialog('setTitle', '账号'+ payment.number +'的交易记录');
			$('#dg-payment-detail').datagrid('options').onBeforeLoad = onBeforeLoadPaymentAccount;
			$('#dg-payment-detail').datagrid('reload');
		}
		var setInitialPaymentDetailTimeFrame = function(timeFrame) 
		{
			var startDate = generateStartDate(timeFrame);
			var endDate = new Date().format("yyyy-MM-dd");
			$('#toolbar-paymentDetail #advanceSearchSpan #startDate').datebox('setValue', startDate);
			$('#toolbar-paymentDetail #advanceSearchSpan #endDate').datebox('setValue', endDate);
		}
		
		var newPaymentAccountCallback = function () {$('#dlg-paymentAccount #fm-paymentAccount #name').focus();}
	</script>
	
	<table id="dg-paymentAccount" title="<spring:message code="navigation.payAccountManagement" />" class="easyui-datagrid" toolbar="#toolbar-paymentAccount" 
		url="<c:url value='/paymentAccount/getAllModel.html' />" fit="true" pagination="false" rownumbers="true" 
		 singleSelect="true" checkOnSelect="true" selectOnCheck="false" data-options="fitColumns:true">
		<thead>
			<tr>
				<th field="id" hidden="true"><spring:message code="id" /></th>
				<th field="name" width="70" sortable="true"><spring:message code="name" /></th>
				<th field="number" width="100" sortable="true">账号</th>
				<th field="action" width="100" data-options="formatter:paymentAccountActionStyler">操作</th>
			</tr>
		</thead>
	</table>
	
	<!-- 查看付款记录弹出框 -->
	<div id="dlg-view-paymentAccount" class="easyui-dialog" 
		style="width: 800px; height: 500px; padding: 5px;" closed="true"
		buttons="#dlg-buttons-view-provider-payment" data-options="modal:true">
		<table id="dg-payment-detail" class="easyui-datagrid"
			style="" url="" rownumbers="true" fit="true"
			singleSelect="true" fitColumns="true" showFooter="true" toolbar="#toolbar-paymentDetail" data-options="pagination:true">
			<thead>
				<tr>
					<th data-options="field:'id',hidden:true"></th>
					<th field="<%=ComponentConstants.PAY_DATE%>" width="50"><spring:message code="order.payDate" /></th>
					<th field="customerName" width="50">客户|供应商</th>
					<th field="operator" width="30">操作者</th>
					<th field="<%=ComponentConstants.PAID%>" width="30">出|入账</th>
					<th field="comment" width="70">备注</th>
				</tr>
			</thead>
		</table>
	</div>
	<div id="toolbar-paymentDetail" style="padding:5px;height:auto">
		<div>
			<span id="advanceSearchSpan" style="width: 610px; display: inline-block;">
				<form id="" action="">
					<input id="paymentId" name="paymentId" type="hidden" />
	            	时间:<input id="startDate" name="startDate" class="easyui-datebox" style="width:100px" 
					editable="false" title="开始时间" data-options="onSelect: onPaymentAccountSelectStartDate" />
					- <input id="endDate" name="endDate" class="easyui-datebox" style="width:100px" 
					editable="false" title="结束时间" data-options="onSelect: onPaymentAccountSelectStartDate" />&nbsp;
					<select id="timeFrame" name="timeFrame" class="easyui-combobox" style="width:80px" panelHeight="auto" editable="false" data-options="onSelect: onPaymentAccountSelectTimeFrame">
						<option value="CUSTOMIZE"><%=TimeFrame.CUSTOMIZE.getText () %></option>
						<option value="TODAY"><%=TimeFrame.TODAY.getText () %></option>
						<option value="RECENT_THREE_DAYS"><%=TimeFrame.RECENT_THREE_DAYS.getText () %></option>
						<option value="RECENT_SEVEN_DAYS" selected="selected"><%=TimeFrame.RECENT_SEVEN_DAYS.getText () %></option>
						<option value="RECENT_FIFTEEN_DAYS"><%=TimeFrame.RECENT_FIFTEEN_DAYS.getText () %></option>
						<option value="RECENT_THIRTY_DAYS"><%=TimeFrame.RECENT_THIRTY_DAYS.getText () %></option>
						<option value="CURRENT_MONTH"><%=TimeFrame.CURRENT_MONTH.getText () %></option>
					</select>
					&nbsp;
					客户:<input id="customerId" name="customerId" class="easyui-combobox" style="width:100px" data-options="valueField:'id',
												textField:'shortName',
												url:'',
												mode:'local',
												filter:comboboxFilter,
												onShowPanel:onClickCustomer" />
					<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" plain="true" title="查询出库单" onclick="onSearchPaymentAccountByAdvance()">查询</a>
				</form>
	        </span>
		</div>
	</div>
	<div id="dlg-buttons-view-provider-payment">
		<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel"
			onclick="javascript:$('#dlg-view-paymentAccount').dialog('close')">关闭</a>
	</div>
	<!-- 查看付款记录弹出框 -->
	
	<div id="toolbar-paymentAccount">
		<a href="javascript:void(0)" class="easyui-linkbutton" 
			iconCls="icon-add" plain="true" onclick="newModel('#dlg-paymentAccount', '新增账号', '#fm-paymentAccount', '<c:url value='/paymentAccount/addModel.html' />', newPaymentAccountCallback)" title="新增账号">新增账号</a> 
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-edit" plain="true" onclick="editModel('#dg-paymentAccount', '#dlg-paymentAccount', '编辑账号', '#fm-paymentAccount', '<c:url value='/paymentAccount/updateModel.html' />', newPaymentAccountCallback)" title="<spring:message code="selectOneRow" />编辑账号">编辑账号</a> 
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-remove" plain="true" onclick="destroyMultipleModel('#dg-paymentAccount', '<spring:message code="paymentAccount" />', '<c:url value='/paymentAccount/deleteModels.html' />', function(){loadGridData ('#dg-paymentAccount', '<c:url value='/paymentAccount/getAllModel.html' />')})" title="<spring:message code="selectOneRow" />删除账号">删除账号</a>
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-reload" plain="true" onclick="loadGridData ('#dg-paymentAccount', '<c:url value='/paymentAccount/getAllModel.html' />')" title="<spring:message code="refresh" />"><spring:message code="refresh" /></a>
	</div>

	<div id="dlg-paymentAccount" class="easyui-dialog"
		style="width: 400px; height: 300px; padding: 10px 20px" closed="true"
		buttons="#dlg-buttons-paymentAccount" data-options="modal:true">
		<form id="fm-paymentAccount" class="fm" method="post" novalidate>
			<div class="fitem divHidden">
				<input name="id" id="paymentAccountId" value="0" />
			</div>
			<div class="fitem">
				<label><spring:message code="name" />:</label> 
				<input id="name" name="name" class="easyui-validatebox" required="true" 
				validType="myRemote['<c:url value='/paymentAccount/checkExist.html' />', 'name', '#paymentAccountId']" />
			</div>
			<div class="fitem">
				<label>账号:</label> 
				<input id="number" name="number" class="easyui-numberbox" required="true" 
				validType="myRemote['<c:url value='/paymentAccount/checkExistByNumber.html' />', 'number', '#paymentAccountId']" 
				onkeyup="if(event.keyCode == 13) {$('#save-paymentAccount').click()}" />
			</div>
		</form>
	</div>
	<div id="dlg-buttons-paymentAccount">
		<a id="save-paymentAccount" href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-ok" onclick="saveModel('#dg-paymentAccount', '#dlg-paymentAccount', '#fm-paymentAccount', function(){loadGridData ('#dg-paymentAccount', '<c:url value='/paymentAccount/getAllModel.html' />')})"><spring:message code="save" /></a> 
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-cancel" onclick="javascript:$('#dlg-paymentAccount').dialog('close')"><spring:message code="cancel" /></a>
	</div>
